// index.js
// 获取应用实例
const app = getApp()
import { request } from "../../request/index.js"
import regeneratorRuntime from "../../lib/runtime/runtime"

Page({
  data: {
    list: [{
      id: 0,
      head: 'https://i2.hdslb.com/bfs/face/cb048764be6e075d1a3e01bd8bdf99a653f3adfe.jpg@150w_150h.jpg',
      auther: '木上野狐',
      text: '虽然在赛后第一时间发布了变化图，但始终不敢做这局棋的复盘。\n不知不觉来到了两个月后。\n慢慢发觉：宝剑锋从磨砺出。\n人生不可能事事如意，挫折与失望，本就是棋与人生的一部分。\n希望柯洁早日拿到第九冠，重归王座！',
      zan: 0,
      liuyan: 0,
      time: '2021-2-2 22:42:42',
      lastTime: '2021-2-4 22:22:22',
      img: [
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/feed-admin/6fc5e4213455a7a0a3c2112e6c1d4ecd7cac5540.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/566725a0f819255990c181e84d0b154bbc990485.jpg@412w_232h_1c.jpg'
      ]
    }, {
      id: 1,
      head: 'https://i2.hdslb.com/bfs/face/cb048764be6e075d1a3e01bd8bdf99a653f3adfe.jpg@150w_150h.jpg',
      auther: '木上野狐',
      text: '我的朋友圈有人才',
      zan: 0,
      liuyan: 0,
      time: '2021-2-2 22:42:41',
      lastTime: '2021-2-4 22:22:22',
      img: [
        'https://i0.hdslb.com/bfs/album/9b321df73f2108d20dbde13504d5e311388206c6.jpg@518w.webp', 
      ]
    }, {
      id: 2,
      head: 'https://i2.hdslb.com/bfs/face/cb048764be6e075d1a3e01bd8bdf99a653f3adfe.jpg@150w_150h.jpg',
      auther: '木上野狐',
      text: '虽然在\n赛后第一时间发布了变化图，但始终不敢做这局棋的复盘。\n不知不觉来到了两个月后。\n慢慢发觉：宝剑锋从磨砺出。\n人生不可能事事如意，挫折与失望，本就是棋与人生的一部分。\n希望柯洁早日拿到第九冠，重归王座！',
      zan: 0,
      liuyan: 0,
      time: '2021-2-2 22:42:42',
      lastTime: '2021-2-4 22:22:22',
      img: [
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg'
      ]
    }, {
      id: 3,
      head: 'https://i2.hdslb.com/bfs/face/cb048764be6e075d1a3e01bd8bdf99a653f3adfe.jpg@150w_150h.jpg',
      auther: '木上野狐',
      text: '虽然在赛后第一时间发布了变化图，但始终不敢做这局棋的复盘。\n不知不觉来到了两个月后。\n慢慢发觉：宝剑锋从磨砺出。\n人生不可能事事如意，挫折与失望，本就是棋与人生的一部分。\n希望柯洁早日拿到第九冠，重归王座！',
      zan: 0,
      liuyan: 0,
      time: '2021-2-2 22:42:42',
      lastTime: '2021-2-4 22:22:22'
    }, {
      id: 4,
      head: 'https://i2.hdslb.com/bfs/face/cb048764be6e075d1a3e01bd8bdf99a653f3adfe.jpg@150w_150h.jpg',
      auther: '木上野狐',
      text: '虽然在赛后第一时间发布了变化图，但始终不敢做这局棋的复盘。\n不知不觉来到了两个月后。\n慢慢发觉：宝剑锋从磨砺出。\n人生不可能事事如意，挫折与失望，本就是棋与人生的一部分。\n希望柯洁早日拿到第九冠，重归王座！',
      zan: 0,
      liuyan: 0,
      time: '2021-2-2 22:42:42',
      lastTime: '2021-2-4 22:22:22',
      img: [
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/51582cc37041ea7bf004d19ab022053ecbc939ff.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/feed-admin/6fc5e4213455a7a0a3c2112e6c1d4ecd7cac5540.jpg@206w_116h_1c_100q.jpg',
        'https://i0.hdslb.com/bfs/archive/566725a0f819255990c181e84d0b154bbc990485.jpg@412w_232h_1c.jpg'
      ]
    }]
  },

  onLoad() {
    this.getPageList()
  },

  async getPageList() {
    const res = await request({
      url: "http://localhost:3000/getPage"
    })
    
    for (let i = 0; i < res.length; i++) {
      let a1 = res[i].img.replace(/ /g, '').replace(/\[/g, '').replace(/\]/g, '').replace(/\\r\\n/g, '').slice(1, -1).split("','")
      res[i].img = a1

      let a2 = res[i].text.replace(/\\n/g, '\n')
      res[i].text = a2
    }
    this.setData({
      list: res
    })
  },


  preview(e) {
    // urls 获取 park 里的所有图片url
    // current 获取当前点击图片url
    const urls = this.data.list[e.currentTarget.dataset.page - 1].img
    const current = e.currentTarget.dataset.url
    wx.previewImage({
      current: current,
      urls: this.data.list[e.currentTarget.dataset.page - 1].img
    })
  },

  handleParkText(e) {
    let stor = this.data.list[e.currentTarget.dataset.pageid - 1]
    wx.setStorageSync('page', stor);
    wx.navigateTo({
      url: '../../pages/page_detail/page_detail?pageid=' + e.currentTarget.dataset.pageid,
    })
  },

  getUserProfile(e) {
    // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        console.log(res)
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    })
  }
})
